package com.societyGames.codeAlong.state.codeExercise.view.menus
{
import com.societyGames.flashForms.DockContainer;
import com.societyGames.flashForms.DockType;
import com.societyGames.flashForms.DockUnitType;
import com.societyGames.flashForms.IDialog;
import com.societyGames.flashForms.TextButton;
import com.societyGames.flashForms.VerticalScrollContainer;
import com.societyGames.flashForms.Window;
import com.societyGames.flashForms.basicSkin.BasicControls;
import com.societyGames.flashForms.basicSkin.SharedTextFields;
import com.societyGames.system.EventObject;

import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.utils.ByteArray;

public class AboutDialog extends EventDispatcher implements IDialog
	{
		[Embed(source="/../assets/About.txt",mimeType="application/octet-stream")]
		private static const aboutTextClass:Class;
		
		private var _completeEventObject:EventObject;
		
		public function AboutDialog()
		{
			this._completeEventObject = new EventObject(this, "COMPLETE");
			initializeInterface();
			
			this._aboutTextField.text = (ByteArray(new aboutTextClass())).toString();
		}
		
		private function okCallback(event:Event):void
		{
			this._completeEventObject.dispatchEvent();
		}
		
		//IDialog-->
		public function get completeEventObject():EventObject
		{
			return this._completeEventObject;
		}
		
		public function get displayObject():DisplayObject
		{
			return this._window;	
		}
		//<--IDialog
		
		private var _window:Window;
		private var _aboutTextField:TextField;
		
		private function initializeInterface():void
		{
			this._window = BasicControls.createWindow("About");
			this._window.width = 260;
			this._window.height = 400;
			
			this._aboutTextField = SharedTextFields.createHtmlTextField();
			this._aboutTextField.autoSize = TextFieldAutoSize.LEFT;
			this._aboutTextField.multiline = true;
			this._aboutTextField.wordWrap = true;
			this._aboutTextField.background = true;
			this._aboutTextField.backgroundColor = 0xFFFFFF;
			
			var okButton:TextButton = BasicControls.createTextButton(okCallback);
			okButton.text = "OK";
			
			var verticalScrollContainer:VerticalScrollContainer = BasicControls.createVerticalScrollContainer();
			verticalScrollContainer.item = this._aboutTextField;
			
			var dockContainer:DockContainer = new DockContainer();
			dockContainer.addItem(okButton, DockType.bottom, DockUnitType.pixel, BasicControls.TEXT_BUTTON_HEIGHT); //Pin it at the current height.
			dockContainer.addItem(verticalScrollContainer, DockType.fill, DockUnitType.percent, 1);
			
			this._window.item = dockContainer;
		}
	}
}